#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Author : Tinfeng


import time
from utils.ReadIni import Read_Ini
from common.BaseDriver import BrowserDriver
from selenium import webdriver
class GetByLocal:
    def __init__(self,i):
        self.browseDriver = BrowserDriver(i)
        self.driver = self.browseDriver.openbrowser(i)


    def get_element(self,key,section=None):
        # 去localelement拿并区分
        read_ini = Read_Ini()
        local =read_ini.get_value(key,section)
        if local != None: #不等于空才执行下面的步骤
            by = local.split('>')[0]
            local_by = local.split('>')[1]
            print(by)
            print(local_by)
            if by == 'classname':
                return self.driver.find_element_by_class_name(local_by)
            elif by == 'xpath':
                return self.driver.find_element_by_xpath(local_by)
            elif by == 'name':
                return self.driver.find_element_by_name(local_by)
            elif by == 'id':
                return self.driver.find_element_by_id(local_by)
            elif by == 'css':
                return self.driver.find_element_by_css_selector(local_by)
        else:
            return None

    # def get_elementB(self,key,section=None):
    #     # 去localelement拿并区分
    #     read_ini = Read_Ini()
    #     local =read_ini.get_value(key,section)
    #     if local != None: #不等于空才执行下面的步骤
    #         by = local.split('>')[0]
    #         local_by = local.split('>')[1]
    #         #print(local_by)
    #         if by == 'classname':
    #             return self.driverB.find_elements_by_class_name(local_by)
    #         elif by == 'xpath':
    #             return self.driverB.find_element_by_xpath(local_by)
    #     else:
    #         return None

if __name__ == '__main__':
    get_by_local = GetByLocal(webdriver)
    # get_by_local.driver()
    get_by_local.get_element('dkdOuter','base').click()


